package com.ym.jiujiangeyou.adapter;

import java.util.List;


import com.ym.jiujiangeyou.R;
import com.ym.jiujiangeyou.adapter.SceneryListAdapter.ViewHolder;
import com.ym.jiujiangeyou.bitmap.ImageLoad1;
import com.ym.jiujiangeyou.bitmap.ImageLoader;
import com.ym.jiujiangeyou.entity.Hotel;
import com.ym.jiujiangeyou.entity.Scenery;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author 叶铭
 * @email yeming_1001@163.com
 * @version V1.0
 * @Description: 住宿列表适配器
 */
public class HotelListAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private Context context;
	private List<Hotel> list;
	private ImageLoader loader ;
	private ImageLoad1 load1 ;

	public HotelListAdapter(Context context) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		loader = new ImageLoader(context) ;
		load1 = new ImageLoad1() ;
	//	loader.setDefaultBitmap(context.getResources().getDrawable(R.drawable.ic_empty)) ;
	}

	public void setData(List<Hotel> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();

	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);

	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;

	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.hotel_list_item, null);
			viewHolder.imageView = (ImageView) convertView
					.findViewById(R.id.hiv_image);
			viewHolder.textView1 = (TextView) convertView
					.findViewById(R.id.h_name);
			viewHolder.textView2 = (TextView) convertView
					.findViewById(R.id.h_address);
			viewHolder.textView3 = (TextView) convertView
					.findViewById(R.id.h_price);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.textView1.setText(list.get(position).getName().toString());
		viewHolder.textView2
				.setText(list.get(position).getAddress().toString());
		viewHolder.textView3.setText(list.get(position).getPrice());
		/*imageLoad.loadImage(list.get(position).getImageurl().toString(),
				viewHolder.imageView);*/
		loader.DisplayImage(list.get(position).getImageurl().toString(), viewHolder.imageView, false) ;
	//	load1.loadImage(list.get(position).getImageurl().toString(), viewHolder.imageView) ;
		return convertView;

	}

	class ViewHolder {
		ImageView imageView;
		TextView textView1, textView2, textView3;
	}

}
